package com.kx.core.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器注册配置
 * @author     Kangx.li 1703054
 * @version    V1 2018年11月22日
 * @since      Java
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer  {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
	System.out.println("WebConfiguration   addInterceptors...............");
	String [] excludes = {"/css/**","/js/**","/images/**","/img/**","/static/**","/error/**"};
	registry.addInterceptor(new UserInterceptor())
	//添加需要拦截的请求 
	.addPathPatterns("/**")                
	//排除不需要拦截的请求
	.excludePathPatterns(excludes);
    }

    /**
     * 注册拦截器，，可以注册多个拦截器
     * @param registry
     */
    
//    @Override
//    protected void addInterceptors(InterceptorRegistry registry) {
//	System.out.println("WebConfiguration   addInterceptors...............");
//	String [] excludes = {"/css/**","/js/**","/images/**","/img/**","/static/**","/error/**"};
//	registry.addInterceptor(new UserInterceptor())
//	//添加需要拦截的请求 
//	.addPathPatterns("/**")                
//	//排除不需要拦截的请求
//	.excludePathPatterns(excludes);             
//    }

//    /**
//     * 默认首页配置
//     */
//    @Override
//    protected void addViewControllers(ViewControllerRegistry registry) {
//	System.out.println("WebConfiguration   默认首页配置...............");
//	registry.addViewController("/").setViewName("forward:/reg");
//	registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
//	super.addViewControllers(registry);
//    }
//
//    /**
//     * 静态资源配置
//     */
//    @Override
//    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
//	System.out.println("WebConfiguration    静态资源配置...............");
//	registry.addResourceHandler("/img/**").addResourceLocations("classpath:/imgs/");
//	super.addResourceHandlers(registry);
//    }

    
}

